package cn.gson.springboot.model.service;




import cn.gson.springboot.model.dao.ComplainDao;
import cn.gson.springboot.model.mapper.ComplainMapper;
import cn.gson.springboot.model.pojos.Complain;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(rollbackFor = Exception.class)
public class ComplainService {
    @Autowired
    ComplainDao complainDao;
    @Autowired
    ComplainMapper complainMapper;

    //新增
    public void addComplain(Complain complain){
        complainDao.save(complain);//一次保存一个对象
    }

    //删除
    public void deleteOne(int complainId){
        complainDao.deleteById(complainId);
    }

    //查找所有
    public List<Complain> selectAll(String search,Integer type){
        return (List<Complain>)complainMapper.selectAll(search, type);
    }
    public List<Complain> selectComplainType(){
        return complainMapper.selectComplainType();
    }

    //根据id修改
    public void alter(int complainId,Complain complain){
         if ( complainDao.findById(complainId)!=null){//找到该对象
             Complain complain1=complainDao.findById(complainId).get();
             complain1.setComplainTheme(complain.getComplainTheme());
             complainDao.save(complain1);
         }
    }
}
